#include "stdafx.h"
#include <boost/format.hpp>
#include "../Utils/ErrorMessage.h"

namespace ja2{ namespace utils
{
	std::string format_window_get_last_error(char const *Function)
	{
		// Get error code
		DWORD const dw = GetLastError(); 
		// Format the error code message
		LPVOID p_message_buffer;
		FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&p_message_buffer, 0, NULL );

		return (boost::format("%s failed with error %d: %s") % Function % dw % static_cast<char *>(p_message_buffer)).str();
	}
} /*utils*/} /*ja2*/